home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / emacs.lha / emacs-19.16 / lisp / studly.el < prev    next >
Lisp/Scheme  |  1993-03-24  |  2KB  |  64 lines

  1. ;;; studly.el --- StudlyCaps (tm)(r)(c)(xxx)
  2.  
  3. ;;; This is in the public domain, since it was distributed
  4. ;;; by its author without a copyright notice in 1986.
  5.  
  6. ;; Keywords: games
  7.  
  8. ;;; Commentary:
  9.  
  10. ;; Functions to studlycapsify a region, word, or buffer.  Possibly the
  11. ;; esoteric significance of studlycapsification escapes you; that is,
  12. ;; you suffer from autostudlycapsifibogotification.  Too bad.
  13.  
  14. ;;; Code:
  15.  
  16. (defun studlify-region (begin end)
  17.   "Studlify-case the region"
  18.   (interactive "*r")
  19.   (save-excursion
  20.     (goto-char begin)
  21.     (setq begin (point))
  22.     (while (and (<= (point) end)
  23.         (not (looking-at "\\W*\\'")))
  24.       (forward-word 1)
  25.       (backward-word 1)
  26.       (setq begin (max (point) begin))
  27.       (forward-word 1)
  28.       (let ((offset 0)
  29.         (word-end (min (point) end))
  30.         c)
  31.     (goto-char begin)
  32.     (while (< (point) word-end)
  33.       (setq offset (+ offset (following-char)))
  34.       (forward-char 1))
  35.     (setq offset (+ offset (following-char)))
  36.     (goto-char begin)
  37.     (while (< (point) word-end)
  38.       (setq c (following-char))
  39.       (if (and (= (% (+ c offset) 4) 2)
  40.            (let ((ch (following-char)))
  41.              (or (and (>= ch ?a) (<= ch ?z))
  42.              (and (>= ch ?A) (<= ch ?Z)))))
  43.           (progn
  44.         (delete-char 1)
  45.         (insert (logxor c ? ))))
  46.       (forward-char 1))
  47.     (setq begin (point))))))
  48.  
  49. (defun studlify-word (count)
  50.   "Studlify-case the current word, or COUNT words if given an argument"
  51.   (interactive "*p")
  52.   (let ((begin (point)) end rb re)
  53.     (forward-word count)
  54.     (setq end (point))
  55.     (setq rb (min begin end) re (max begin end))
  56.     (studlify-region rb re)))
  57.  
  58. (defun studlify-buffer ()
  59.   "Studlify-case the current buffer"
  60.   (interactive "*")
  61.   (studlify-region (point-min) (point-max)))
  62.  
  63. ;;; studly.el ends here
  64.